import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;

public class E24_MapOrder {

	static Random rand = new Random();

	public static void main(String[] args) {

		Map<String, Integer> map = new LinkedHashMap<String, Integer>();

		for (int i = 0; i < 10000; i++) {
			int key = rand.nextInt(50);
			Integer freq = map.get(key + "");
			map.put(key + "", freq == null ? 1 : freq + 1);
		}

		System.out.println(map);
		
		String[] keys = map.keySet().toArray(new String[0]);
		Arrays.sort(keys);
		Map<String, Integer> m2 = new LinkedHashMap<String, Integer>();
		for (String key : keys)
			m2.put(key, map.get(key));
		System.out.println(m2);
	}

}
